package com.a3dweijing.wetouch2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.a3dweijing.wetouch2.Activity.GoodsOrOrderItem;
import com.a3dweijing.wetouch2.Common.RefreshRecycler.CommonrRecyclerAdapter;
import com.a3dweijing.wetouch2.Common.RefreshRecycler.ViewHolder;
import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.GlideUtil;
import com.a3dweijing.wetouch2.Util.Util;
import com.a3dweijing.wetouch2.bean.GoodsListBean;
import com.a3dweijing.wetouch2.bean.OrderListBean;
import com.a3dweijing.wetouch2.bean.PendingPaymentMsg;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/3/30.
 */

public class GoodsByOrderAdapter extends CommonrRecyclerAdapter
{
    
    private OrderListBean orderListBean;
    
    public void setOrderListBean(OrderListBean item)
    {
        this.orderListBean = item;
    }
    
    public GoodsByOrderAdapter(Context context, List datas)
    {
        super(context, datas);
    }
    
    @Override
    public int getItemCount()
    {
        return mDatas.size() + 1;
    }
    
    @Override
    public void convert(RecyclerView.ViewHolder holder, Object o)
    {
        ViewHolder holder1 = (ViewHolder)holder;
        if (holder1.flag == 0)
        {
            TextView name = holder1.getView(R.id.name);
            TextView number = holder1.getView(R.id.number);
            TextView address = holder1.getView(R.id.address);
            name.setText("收件人：" + orderListBean.getConsignee());
            number.setText("联系电话：" + orderListBean.getConsignee_tel());
            address.setText("收货地址：" + orderListBean.getAddress());
        }
        else
        {
            GoodsListBean item = (GoodsListBean)o;
            ImageView imageView = holder1.getView(R.id.img);
            TextView shopping_name = holder1.getView(R.id.shopping_name);
            TextView num = holder1.getView(R.id.num);
            TextView all_money = holder1.getView(R.id.all_money);
            GlideUtil.getInstance().showImage(mContext, item.getGoods_imgurl(), imageView);
            shopping_name.setText(item.getGoods_name());
            num.setText("x" + item.getGoods_number() + "");
            all_money.setText(
                Util.multiplication(item.getGoods_money(), String.valueOf(item.getGoods_number())).toString() + "");
            
        }
    }
    
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        if (viewType == 0)
            return ViewHolder.get(mContext, parent, R.layout.goodbyorder_top, viewType);
        else
        {
            return ViewHolder.get(mContext, parent, R.layout.goodbyorder, viewType);
        }
    }
    
    @Override
    public int getItemViewType(int position)
    {
        if (position == 0)
            return 0;
        else
            return 1;
    }
    
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
    {
        if (position > 0)
            convert(holder, mDatas.get(position - 1));
        else
            convert(holder, orderListBean);
    }
}
